package com.datacloud.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.datacloud.bean.TiresBean;
import com.datacloud.dao.TireEventsDao;
import com.datacloud.dao.TiresDao;
import com.datacloud.service.InventoryManageService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * Created by QKY on 2016/10/18.
 */
@Service
public class InventoryManageServiceImpl implements InventoryManageService {
    @Autowired
     TiresDao tiresDao;
    @Autowired
    TireEventsDao tireEventsDao;
//    库存盘点
    @Override
    public  JSONObject getInventoryTire(int stockid){
        JSONObject result= new JSONObject();
        List<Map<String,Object>>list=tiresDao.inventoryTireInfo(stockid);
        result.put("success",true);
        result.put("msg","");
        result.put("data",list);
        return result;
    }
    /**
     * 翻新盘点
     */
    @Override
    public JSONObject getRecappedTire(int stockid){
        JSONObject result =new JSONObject();
        List<Map<String,Object>> list = tiresDao.recappedTireInfo(stockid);
        result.put("success",true);
        result.put("msg","");
        result.put("data",list);
        return result;
    }
    /**
     * 获取所有的处理意见
     */
    @Override
    public JSONObject findAllMemoInfo(){
        JSONObject result =new JSONObject();
        List<TireEventsDao>list=tireEventsDao.findAllMemo();
        result.put("success",true);
        result.put("msg","");
        result.put("data",list);
        return result;
    }

    //    通过stockid获得所有翻新轮胎信息
    @Override
    public JSONObject getRenovatedTyreByStockid(int stockid){
        JSONObject result = new JSONObject();
        List<Map<String,Object>>getRenovatedTyreByStockid=tiresDao.getRenovatedTyreByStockid(stockid);
        result.put("",getRenovatedTyreByStockid);
        return result;
    }
    //    通过stockid获得所有配送轮胎信息
    @Override
    public JSONObject getDistributionTireByStockid(int stockid){
        JSONObject result = new JSONObject();
        List<Map<String,Object>>getDistributionTireByStockid=tiresDao.getDistributionTireByStockid(stockid);
        result.put("",getDistributionTireByStockid);
        return result;
    }

//    轮胎出库
    @Override
    public boolean tireOutgoing(int tireid,int aimid,int stockid){
        int tire = tiresDao.tireOutgoing(tireid,aimid);
        int event =tireEventsDao.tireOutgoing(tireid,stockid);
        if (tire>0 && event>0){
            return true;
        }
        else {
            return false;
        }
    }
//翻新轮胎入库
    @Override
    public boolean renovatedTire(List<String> tirelist,int stockid){
        int i=0;
        for (String tires: tirelist
             ) {
            i++;
            int tireid=Integer.parseInt(tirelist.get(i).toString());
            int renovatedTire =tiresDao.renovatedTire(tireid);
            int renovated = tireEventsDao.renovated(tireid,stockid);

            if (renovated>0 && renovatedTire>0){

            }
            else {
                return false;
//                break;
            }
        }
        return true;
    }

//配送轮胎入库
    @Override
    public boolean distributionTire(List<String> tirelist,int stockid){
        int i=0;
        for (String tires: tirelist
                ) {
            i++;
            int tireid=Integer.parseInt(tirelist.get(i).toString());
            int renovatedTire =tiresDao.distributionTire(tireid);
            int renovated = tireEventsDao.distribution(tireid,stockid);

            if (renovated>0 && renovatedTire>0){

            }
            else {
                return false;
//                break;
            }
        }
        return true;
    }
}
